// 
//  Copyright (C) 2009 Jacek Trubłajewicz
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 

using System;

namespace wxGadu
{
	/// <summary>
	/// Represents single message in chat
	/// </summary>
	public class ChatMessage
	{
		private int uin;
		private string name;
		private System.DateTime time;
		private string message;
		private string formattedMessage;
		private MessageFormatter formatter;
			
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="uin">
		/// A <see cref="System.Int32"/>
		/// message author UIN
		/// </param>
		/// <param name="name">
		/// A <see cref="System.String"/>
		/// message author name
		/// </param>
		/// <param name="time">
		/// A <see cref="System.DateTime"/>
		/// message sending/receiving time
		/// </param>
		/// <param name="message">
		/// A <see cref="System.String"/>
		/// message body
		/// </param>
		/// <param name="formatter">
		/// A <see cref="MessageFormatter"/>
		/// object that can transform raw message body into HTML version
		/// </param>
		public ChatMessage(int uin, string name, System.DateTime time, string message, MessageFormatter formatter)
		{
			this.uin = uin;
			this.name = name;
			this.time = time;
			this.message = message;
			this.formatter = formatter;
			this.formattedMessage = string.Empty;
		}
		
		//// <value>
		/// Formatted (HTML) message body
		/// </value>
		public string FormattedMessage
		{
			get 
			{
				if (formattedMessage != string.Empty)
					return formattedMessage; 
				else
				{
					formattedMessage = formatter.FormatMessage(this);
					return formattedMessage;
				}
			}
			set { formattedMessage = value; }
		}
		
		//// <value>
		/// Message author UIN
		/// </value>
		public int Uin
		{
			get { return uin; }
		}
		
		//// <value>
		/// Message author name
		/// </value>
		public string Name
		{
			get { return name; }
		}
		
		//// <value>
		/// Sending/receiving time
		/// </value>
		public System.DateTime Time
		{
			get { return time; }
		}
		
		//// <value>
		/// Raw message body
		/// </value>
		public string Message
		{
			get { return message; }
		}
	}
}
